package com.wu.service.impl;

import com.wu.mappers.ProductsMapper;
import com.wu.pojo.Products;
import com.wu.pojo.vo.CateGoriesVo;
import com.wu.pojo.vo.ProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.wu.mappers.CategoriesMapper;
import com.wu.pojo.Categories;
import com.wu.service.CategoriesService;

import java.util.List;

/**
@author sun
@date 2022/3/27 - 23:04
*/
@Service
public class CategoriesServiceImpl implements CategoriesService{

    @Resource
    private CategoriesMapper categoriesMapper;
    @Autowired
    private ProductsMapper productsMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return categoriesMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Categories record) {
        return categoriesMapper.insert(record);
    }

    @Override
    public int insertSelective(Categories record) {
        return categoriesMapper.insertSelective(record);
    }

    @Override
    public Categories selectByPrimaryKey(Integer id) {
        return categoriesMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Categories record) {
        return categoriesMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Categories record) {
        return categoriesMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<CateGoriesVo> findCategoriesVo(Categories categories) {
        List<CateGoriesVo> cateGoriesVoList=categoriesMapper.findCategoriesVo(categories);
        if (cateGoriesVoList!=null){
            cateGoriesVoList.forEach(e->{
                //获取分类id
                 Integer id = e.getId();
                 //通过分类id查询商品
                 Products products = new Products();
                 products.setCategoryId(id);
                 products.setCategoriesId(id);
                 List<ProductVo> productVoList = productsMapper.findProductsVo(products);
                 e.setProductVoList(productVoList);
            });
        }
        return cateGoriesVoList;
    }

}
